package com.king.collect;

import com.google.common.base.Splitter;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

/**
 * Created by Administrator on 2015/4/23.
 */
//本质是set加了一个计数器，可以有重复的值
public class MultisetDemo {
    public static void main(String[] args) {
        Multiset multiset = HashMultiset.create();
        String sentences = "this is a story,there is a good girl in the story";
        //^[a-z] 匹配以小写字母开头的文本串 [^a-z] 表示与不包含小写字母的字符匹配
        Iterable<String> words = Splitter.onPattern("[^a-z]{1,}").omitEmptyStrings().split(sentences);
        for (String word :words){
            multiset.add(word);
        }
        for(Object element: multiset){
            System.out.println(element+":"+multiset.count(element));
        }
    }
}
